package com.asp.alumnisystem.app;

import android.app.Application;
import android.content.Context;

import com.asp.alumnisystem.model.UserModel;
import com.tencent.mmkv.MMKV;

/**
 * 全局App，保存用户信息，提供context
 */
public class App extends Application {

    private static App context;

    private UserModel userModel;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        MMKV.initialize(getAppContext().getExternalFilesDir("cache").getAbsolutePath());
    }

    public static Context getAppContext(){
        return context.getApplicationContext();
    }

    public static App getApp(){
        return context;
    }

    public UserModel getUserModel() {
        return userModel;
    }

    public Long getUserId(){
        if (userModel != null){
            return userModel.getUserId();
        }
        return -1L;
    }

    public void setUserModel(UserModel userModel) {
        this.userModel = userModel;
    }

    public boolean isVisitor(){
        if (userModel != null){
            return userModel.isVisitor();
        }
        return true;
    }
}
